USE [kb.net]
GO

/****** Object:  Trigger [dbo].[PIN_Archive]    Script Date: 6/29/2012 5:50:39 PM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO





-- =============================================
-- Author:		R. Brian Amesbury
-- Create date: 14 June 2012
-- Description:	Keeps a history of Account PIN
-- =============================================
CREATE TRIGGER [dbo].[PIN_Archive] 
   ON  [dbo].[Account_PIN] 
   AFTER UPDATE
AS 
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for trigger here
	DECLARE @ID int
	SET @ID = (SELECT ID FROM deleted)
	DECLARE @PIN varchar(50)
	SET @PIN = (SELECT PIN FROM deleted)
	DECLARE @DateStart datetime2
	SET @DateStart = (SELECT ModifyDate FROM deleted)
	DECLARE @DateEnd datetime2
	SET @DateEnd = (SELECT ModifyDate FROM inserted)

	INSERT INTO [dbo].[Account_PIN_History]
		(
			ID,
			PIN,
			DateStart,
			DateEnd
		)
	VALUES
		(
			@ID,
			@PIN,
			@DateStart,
			@DateEnd
		)
END





GO

